import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store';
import Element, {MessageBox} from 'element-ui'
Element.Dialog.props.closeOnClickModal.default = false;
Vue.use(Element)
// 导入字体图标
import './assets/fonts/iconfont.css'
// 导入全局样式表
import './assets/css/global.css'
import TreeTable from 'vue-table-with-tree-grid'

import dataV from '@jiaminghi/data-view';
// 引入全局css
import './assets/scss/style.scss';
// 按需引入vue-awesome图标
import Icon from 'vue-awesome/components/Icon';
import 'vue-awesome/icons/chart-bar.js';
import 'vue-awesome/icons/chart-area.js';
import 'vue-awesome/icons/chart-pie.js';
import 'vue-awesome/icons/chart-line.js';
import 'vue-awesome/icons/align-left.js';

//引入echart
//4.x 引用方式
import echarts from 'echarts'
//5.x 引用方式为按需引用
//希望使用5.x版本的话,需要在package.json中更新版本号,并切换引用方式
//import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts
Vue.config.productionTip = false;
// 全局注册
Vue.component('icon', Icon);
Vue.use(dataV);




// 导入 NProgress 包对应的JS和CSS
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// 导入moment
import moment from 'moment'
import _ from 'lodash'

import axios from 'axios'
Vue.prototype.$moment = moment
Vue.prototype.$_ = _
moment.locale('zh-cn')
// 配置请求的跟路径
// axios.defaults.baseURL = 'http://114.55.100.216/gm/web/'
axios.defaults.baseURL = 'http://39.98.56.112//gm/web/'
// axios.defaults.baseURL = 'http://localhost:8090/'
// 在 request 拦截器中，展示进度条 NProgress.start()
axios.interceptors.request.use(config => {
  // console.log(config)
  NProgress.start()
  config.headers.Authorization = window.sessionStorage.getItem('token')
  // 在最后必须 return config
  return config
})
// 在 response 拦截器中，隐藏进度条 NProgress.done()
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})
Vue.prototype.$http = axios

/* 请求下载文件流*/
export function fetchPostDataBlob(url, params) {
  // 加载动画
  return new Promise((resolve, reject) => {
    axios.post(url, params, {responseType: 'blob'})
      .then(function (res) {
        if (res.status >= 200 && res.status < 300) {
          if ((res.data.code == '0' && res.data.businessCode == '-10001') || (res.data.code == '0' && res.data.businessCode == '20001')) {
            errorMsg()
          } else {
            return resolve(res.data)
          }
        } else {
          return reject(new Error(res.status))
        }
      })
      .catch(function (err) {
        console.log(err)
      })
  })
}
// blob文件流下载
export function downloadFile (data, filename){
  const url = window.URL.createObjectURL(new Blob([data]))
  const link = document.createElement('a')
  const fileName = filename
  link.style.display = 'none'
  link.href = url
  link.setAttribute('download', fileName)
  document.body.appendChild(link)
  link.click()
  URL.revokeObjectURL(link.href)
  document.body.removeChild(link)
}

function errorMsg() {
  if (sessionStorage.length > 0 && !window.isErrorDong) {
    window.isErrorDong = true;
    MessageBox.confirm('出错', '提示', {
      cancelButtonText: '取消',
      type: 'warning'
    })
  }
}



Vue.config.productionTip = false

Vue.component('tree-table', TreeTable)
// 将富文本编辑器，注册为全局可用的组件
// Vue.use(VueQuillEditor)

Vue.filter('dateFormat', function (originVal) {
  const dt = new Date(originVal)

  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})


new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount('#app');
